﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Web;

namespace SpyApp.Models
{
    public class FakeMake
    {
        
        public static void RandomObject<T>(Random random, T temp)
        {
            Type type = typeof(T);
            System.Reflection.PropertyInfo[] pFrom = type.GetProperties();
            foreach (System.Reflection.PropertyInfo p in pFrom)
            {
                System.Reflection.PropertyInfo pInfo = type.GetProperty(p.Name);
                if (p.PropertyType.Name.ToLower() == "string")
                {
                    string value = randomString(random, p.Name);
                    pInfo.SetValue(temp, value, null);
                    //pInfo.SetValue(temp, "nghia", null);
                } else try
                {
                    int value = random.Next();
                    pInfo.SetValue(temp, value, null);
                }
                catch { }
            }
        }

        public static User FakeUser()
        {
            int Seed = (int)DateTime.Now.Ticks;
            Random random = new Random(Seed);
            User user = new User()
            {
                ActiveInvationCode = randomString(random, "ActiveInvationCode"),
                Age = random.Next(1, 100),
                Id = random.Next(1, 100).ToString(),
                UserName = randomString(random, "username"),
                PassWord = randomString(random, "password"),
            };
            return user;
        }

        public static Device FakeDevice()
        {
            Random random = new Random();
            Device device = new Device()
            {
                AppInstalledOn = randomString(random, "AppinstalledOn"),
                AppVersion = randomString(random, "appversion"),
                DeviceName = randomString(random, "DeviceName "),
                Id = randomString(random, "id"),
                Imei1 = randomString(random, "IDME1"),
                Imei2 = randomString(random, "IDME2"),
                OsBrand = randomString(random, "ÓSBrand"),
                OsVersion = randomString(random, "osVersion"),
                ScreenSize = randomString(random, "SCREENSIze"),
                Sn = randomString(random, "SN"),
            };
            return device;
        }

        //public static AccountModel.AdminView FakeAccountAdminView()
        //{
        //    AccountModel.AdminView temp = new AccountModel.AdminView();
            
        //    return temp;
        //}

        public static Message FakeMessage()
        {
            Random random = new Random();
            Message message = new Message()
            {
                Id = randomString(random, "messageid"),
                NumberSendReceive = randomString(random, "numbersendrêcive"),
                SendDateTime = DateTime.Today,
                Type = BaseCommon.Enum.DBEntity.SendReceiveType.Receive,
                UserMessage = randomString(random, "usermessage dddddddddd dddddddd ddddddddddd dddddddddd dddddd dddddd")
            };
            return message;
        }

        public static string randomString(Random ramdom, string refix = "refix", int minNumber = 1, int maxNumber = 100){
            // ramdom phải ở ngoài vì trùng số
            string str_return = "";
            str_return = refix + "_" + ramdom.Next(minNumber, maxNumber);
            return str_return;
        }

        
    }
}